<?php

use Laravel\Lumen\Application;

class UserApplication extends Application
{

    /**
     *  Create a new Lumen application instance.
     *
     * @param string|null  $basePath
     */
    public function __construct($basePath = null)
    {
        parent::__construct($basePath);
    }

    /**
     * Get the path to the given configuration file.
     *
     * If no name is provided, then we'll return the path to the config folder.
     *
     * @param  string|null  $name
     * @return string
     */
    public function getConfigurationPath($name = null)
    {
        if (! $name) {
            $appConfigDir = $this->basePath('config').'/';

            $env =$this->environment();
            if (file_exists($appConfigDir.$env.'/')) {
                return $appConfigDir.$env.'/';
            } else if (file_exists($appConfigDir)) {
                return $appConfigDir;
            } elseif (file_exists($path = __DIR__.'/../config/')) {
                return $path;
            }
        } else {
            $appConfigDir = $this->basePath('config').'/';
            $appConfigPath = $this->basePath('config').'/'.$name.'.php';

            $env =$this->environment();
            if (file_exists($appConfigDir.$env.'/'.$name.'.php')) {
                return $appConfigDir.$env.'/'.$name.'.php';
            } else if (file_exists($appConfigPath)) {
                return $appConfigPath;
            } elseif (file_exists($path = __DIR__.'/../config/'.$name.'.php')) {
                return $path;
            }
        }
    }

}
